package com.xiaoyu.client.ui.activity.main.mine.collect_and_refundafter;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.xiaoyu.client.R;
import com.xiaoyu.client.network.NetworkManager;
import com.xiaoyu.commonlib.network.CommonHttpResponser;
import com.xiaoyu.commonlib.ui.base.BaseActivityWithTitle;
import com.xiaoyu.commonlib.utils.CommonFragmentPagerAdapter;
import com.xiaoyu.commonlib.utils.ViewPagerUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author jx
 * @date 创建时间 2018/10/18
 * @Description 收藏
 */
public class CollectActivity extends BaseActivityWithTitle implements ViewPager.OnPageChangeListener {

    @BindView(R.id.post)
    TextView mPost;
    @BindView(R.id.shop)
    TextView mShop;
    @BindView(R.id.activity_collect_viewpager)
    ViewPager mViewPager;
    @BindView(R.id.activity_sign_line)
    View mBarLine;
    @BindView(R.id.activity_collect_linear)
    LinearLayout mBarView;

    private List<Fragment> fragments = new ArrayList<>();
    private CommonFragmentPagerAdapter managementAdapter;
    private ViewPagerUtils mPagerUtils;

    @Override
    protected void loadContentView(ViewGroup parent) {
        LayoutInflater.from(this).inflate(R.layout.activity_collect, parent, true);
        setTitleText("我的收藏");
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        mPost.setOnClickListener(this);
        mShop.setOnClickListener(this);


        fragments.add(new PostFragment());//帖子
        fragments.add(new ShopFragment());//商品

        managementAdapter = new CommonFragmentPagerAdapter(getSupportFragmentManager(), fragments);
        mViewPager.setAdapter(managementAdapter);
        mViewPager.addOnPageChangeListener(this);
        //默认显示第一个
        mViewPager.setCurrentItem(0);
        mPagerUtils = new ViewPagerUtils(this, mBarView, mBarLine);
        mPagerUtils.initLine(50);
        mPagerUtils.setTextColor("#333333", "#0c93e9");
        mPagerUtils.selectItem(0);

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (v == mPost) {
            mViewPager.setCurrentItem(0, true);
            mPagerUtils.selectItem(0);
        }
        if (v == mShop) {
            mViewPager.setCurrentItem(1, true);
            mPagerUtils.selectItem(1);
        }
    }


    /**
     * viewpager的切换监听事件
     */
    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        mPagerUtils.scrollLineMove(position, positionOffset);
    }

    @Override
    public void onPageSelected(int position) {
        mPagerUtils.selectItem(position);
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
